import request from './axios'
import axios from './axios'
import { requestHandle } from "./axios";
import { API_PREFIX } from "@/assets/js/dict"

/**
 *  --------------------------------------- 家长登录 Start ---------------------------------------
 */

/**
 * 获取注册用的图形验证码
 * 
 * @method GetCheckCode
 * 
 * 
 * @return 
 * {
    "error": "no response from server"
    }
 */

export function GetCheckCode (params, call) {
    requestHandle(request({
        url: '/anonymous/parent/action/checkCodeForSignIn',
        method: 'get',
        params
    }), call)
}

/**
 * 查看用户名是否已经注册
 * 
 * @method GetCheckNameForParentSignIn
 * 
 * @param {String} username 用户名
 * 
 * @example 
 * {
    "username": "",  用户名   String类型
 * }
 *
 * @return 
 * {
    "error": "no response from server"
    }
 */
export function GetCheckNameForParentSignIn (params) {
    return request({
        url: '/anonymous/parent/action/checkNameForParentSignIn',
        method: 'get',
        params
    })
}


/**
 * 查看手机号是否已经注册
 * 
 * @method GetCheckPhoneForParentSignIn
 * 
 * @param {String} phone 手机号
 * 
 * @example 
 * {
    "phone": "",  手机号   String类型
 * }
 *
 * @return 
 * {
    "error": "no response from server"
    }
 */
export function GetCheckPhoneForParentSignIn (params, call) {
    requestHandle(request({
        url: '/anonymous/parent/action/checkPhoneForParentSignIn',
        method: 'get',
        params
    }), call);
}

/**
 * 获取注册用的短信验证码
 * 
 * @method GetPhoneCodeForSignIn
 * 
 * @param {String} phone 手机号
 * @param {String} code 验证码
 * @param {String} flag 
 * 
 * @example 
 * {
    "phone": "",  手机号   String类型
    "code": "",  验证码   String类型
    "flag": "",
 * }
 *
 * @return 
 * {
    "error": "no response from server"
    }
 */
export function GetPhoneCodeForSignIn (params, call) {
    requestHandle(request({
        url: '/anonymous/parent/action/phoneCodeForSignIn',
        method: 'get',
        params
    }), call)
}

/**
 * 家长注册
 * 
 * @method PostSignIn
 * 
 * @param {Object} params 
 * 
 * @example 
 * { 
    create_time (string, optional), // 创建时间
    gender (string, optional) = ['男', '女'], 性别
    id (integer, optional),
    is_vip (boolean, optional), // 是否为VIP
    kids (Array[Student], optional), // 学生
    last_pay_time (string, optional), // 付款时间
    name (string, optional), // 名称
    password (string, optional), // 密码
    phone (string, optional), // 手机号
    role (string, optional) = ['ADMIN', 'PARENT', 'TUTOR'] // 角色 【管理员 / 家长 / 家教】
    site (string, optional), // 位置
    update_time (string, optional),
    vip_limit (string, optional),
    wx_open_id (string, optional),
    wx_union_id (string, optional)
 * }
 *
 * @return 
 * {
    "error": "no response from server"
    }
 */
export function PostSignIn (params, call) {
    requestHandle(request({
        url: '/anonymous/parent/action/signIn',
        method: 'post',
        data: params
    }), call)
}


/**
 * 家长登录
 * 
 * @method PostParentLogin
 * 
 * @param {Object} params 
 * 
 * @example 
 * { 
    username: '', // 名称
    password: '', // 密码 
* }
*
* @return 
* {
    "error": "no response from server"
  }
*/
export function PostParentLogin (params) {
    return request({
        url: '/login/parentLogin',
        method: 'post',
        data: params
    })
}


/**
 * 家长须知
 * 
 * @method GetParentKnowHtml
 * 
 */

export function GetParentKnowHtml (params) {
    return request({
        url: '/view/parentKnowHtml',
        method: 'get',
        params
    })
}


/**
 * 家长协议
 * @param params
 * @returns {AxiosPromise}
 */
export function parentProtocolHtml (params, call) {
    requestHandle(request({
        url: '/view/parentProtocolHtml',
        method: 'get',
        params
    }), call);
}



/**
 * 常见问题
 * 
 * @method GetParentFaqOfTutor
 * 
 */

export function GetParentFaqOfTutor (params) {
    return request({
        url: '/parent/action/faqOfTutor',
        method: 'get',
        params
    })
}

/**
 * 客服中心
 * 
 * @method GetParentCallCenterOfTutor
 * 
 */
export function GetParentCallCenterOfTutor (params) {
    return request({
        url: '/parent/action/callCenterOfTutor',
        method: 'get',
        params
    })
}




/**
 *  --------------------------------------- 家长登录 End ---------------------------------------
 */



/**
 *  --------------------------------------- 家教注册 Start --------------------------------------
 */


/**
 * 获取家教注册用的图形验证码
 * 
 * @method GetTutorCheckCode
 * 
 * 
 * @return 
 * {
    "error": "no response from server"
    }
 */

export function GetTutorCheckCode (params, call) {
    requestHandle(request({
        url: '/anonymous/tutor/action/checkCodeForSignIn',
        method: 'get',
        params
    }), call);
}

/*
* 上传图片的接口
* */
export function uploadPict (params, callback) {
    var forms = new FormData();
    var configs = {
        headers: { 'Content-Type': 'multipart/form-data' }
    };
    forms.append('file', params.file);
    forms.append("note", params.note);
    requestHandle(axios.post(`${API_PREFIX}/anonymous/document/action/upload`, forms, configs), callback);
}

/*
* 删除图片的接口
* */
export function deleteFile (params) {
    return request({
        url: '/anonymous/document/action/delete',
        method: 'post',
        params
    })
}

/*
* 查看图片的接口
* */
export function previewPict (file_id) {
    return `${API_PREFIX}/anonymous/document/action/preview?file_id=${file_id}`;
}

export function parentKnow (callback) {
    requestHandle(request({
        url: `${API_PREFIX}/view/parentKnow`,
        method: 'get'
    }), callback)
}


/**
 * 查看家教用户名是否已经注册
 * 
 * @method GetTutorCheckNameForParentSignIn
 * 
 * @param {String} username 用户名
 * 
 * @example 
 * {
    "username": "",  用户名   String类型
 * }
 *
 * @return 
 * {
    "error": "no response from server"
    }
 */
export function GetTutorCheckNameForParentSignIn (params, call) {
    requestHandle(request({
        url: '/anonymous/tutor/action/checkNameForParentSignIn',
        method: 'get',
        params
    }), call);
}

/**
 * 查看家教手机号是否已经注册
 * 
 * @method GetTutorCheckPhoneForParentSignIn
 * 
 * @param {String} phone 手机号
 * 
 * @example 
 * {
    "phone": "",  手机号   String类型
 * }
 *
 * @return 
 * {
    "error": "no response from server"
    }
 */
export function GetTutorCheckPhoneForParentSignIn (params, call) {
    requestHandle(request({
        url: '/anonymous/tutor/action/checkPhoneForSignIn',
        method: 'get',
        params
    }), call);
}

/**
 * 获取家教注册用的短信验证码
 * 
 * @method GetTutorPhoneCodeForSignIn
 * 
 * @param {String} phone 手机号
 * @param {String} code 验证码
 * @param {String} flag 
 * 
 * @example 
 * {
    "phone": "",  手机号   String类型
    "code": "",  验证码   String类型
    "flag": "",
 * }
 *
 * @return 
 * {
    "error": "no response from server"
    }
 */
export function GetTutorPhoneCodeForSignIn (params, call) {
    requestHandle(request({
        url: '/anonymous/tutor/action/phoneCodeForSignIn',
        method: 'get',
        params
    }), call)
}


/**
 * 家教注册
 * 
 * @method PostTutorSignIn
 * 
 * @param {Object} params 
 * 
 * @example 
 * { 
    name: '', // 姓名
    password: '', // 密码 
    phone: '', // 电话 
    wx_open_id: '', // 微信用户应用id	 
    wx_union_id: '', // 微信用户id 
    gender:'', // 性别 
* }
*
* @return 
* {
    "error": "no response from server"
  }
*/
export function PostTutorSignIn (params, call) {
    requestHandle(request({
        url: '/anonymous/tutor/action/signIn',
        method: 'post',
        data: params
    }), call);
}



/**
 * 家教须知
 * 
 * @method GetTutorKnowHtml
 * 
 */

export function GetTutorKnowHtml (params) {
    return request({
        url: '/view/tutorKnowHtml',
        method: 'get',
        params
    })
}

/**
 * 家教协议
 * @param params
 * @returns {AxiosPromise}
 * @constructor
 */
export function tutorProtocolHtml (params, call) {
    requestHandle(request({
        url: '/view/tutorProtocolHtml',
        method: 'get',
        params
    }), call);
}



/**
 * 常见问题
 * 
 * @method GetTutorFaqOfTutor
 * 
 */

export function GetTutorFaqOfTutor (params) {
    return request({
        url: '/tutor/action/faqOfTutor',
        method: 'get',
        params
    })
}

/**
 * 客服中心
 * 
 * @method GetTutorCallCenterOfTutor
 * 
 */
export function GetTutorCallCenterOfTutor (params) {
    return request({
        url: '/tutor/action/callCenterOfTutor',
        method: 'get',
        params
    })
}



/**
 *  --------------------------------------- 家教注册 End --------------------------------------
 */


/**
 *  --------------------------------------- 家教登录 Start --------------------------------------
 */

/**
 * 家长登录
 * 
 * @method PostTutorLogin
 * 
 * @param {Object} params 
 * 
 * @example 
 * { 
    username: '', // 名称
    password: '', // 密码 
* }
*
* @return 
* {
    "error": "no response from server"
  }
*/
export function PostTutorLogin (params) {
    return request({
        url: '/login/tutorLogin',
        method: 'post',
        data: params
    })
}





/**
 *  --------------------------------------- 家教登录 End --------------------------------------
 */



/**
 *  --------------------------------------- 家教简历 Start--------------------------------------
 */

/**
 * 家教简历新增
 * 
 * @method GetTutorActionAdd
 * 
 * @param {Object} params 
 * 
 * @example 
    * {
        applying_order (string, optional), // 申请订单
        class_type (string, optional) = ['文科', '理科'], // 类型
        code (string, optional), 
        college (string, optional), // 大学 学院
        college_biology (string, optional), // 生物学 
        college_chemie (string, optional), // 化学
        college_english (string, optional), // 英语
        college_geography (string, optional), // 地理
        college_history (string, optional), // 历史
        college_language (string, optional), // 汉语
        college_math (string, optional), // 数学
        college_physics (string, optional), // 物理
        college_politics (string, optional),// 政治
        college_school_province (string, optional), // 大学所在省
        college_score_ranking (string, optional), // 大学成绩排名
        create_time (string, optional), // 创建时间
        email (string, optional), // 邮箱
        experience (string, optional), // 家教经验（最好包括辅导时间、学生学校年级、科目和效果）
        gender (string, optional) = ['男', '女'], // 性别
        grade (string, optional), // 等级
        high_biology (string, optional), // 高中生物学
        high_chemie (string, optional), // 高中化学
        high_english (string, optional), // 高中英语
        high_geography (string, optional), // 高中地理
        high_history (string, optional), // 高中历史
        high_language (string, optional), // 高中汉语
        high_math (string, optional), // 高中数学
        high_physics (string, optional), // 高中物理
        high_politics (string, optional), // 高中政治
        high_school_province (string, optional), // 高中所在省
        high_score_ranking (string, optional), // 高中排名
        id (integer, optional),
        name (string, optional), // 姓名
        password (string, optional), // 密码
        phone (string, optional), // 手机 
        pict (string, optional), // 图片
        prize (string, optional), // 获奖情况（学习相关、学习无关均可）
        profession (string, optional), // 职业
        role (string, optional) = ['ADMIN', 'PARENT', 'TUTOR'], // 角色【管理员 / 家长 / 家教】
        school (string, optional), // 学校名称
        self_evaluation (string, optional), // 自我评估
        skilled_grades (string, optional), // 技术等级
        skilled_subjects (string, optional), // 熟练的科目
        teaching_idea (string, optional), // 教学理念
        teaching_orders (string, optional), // 教学指令
        update_time (string, optional),
        wx_open_id (string, optional),
        wx_union_id (string, optional)
 * }
 *
 * @return 
 * {
    "error": "no response from server"
    }
 */
export function GetTutorActionAdd (params) {
    return request({
        url: '/tutor/action/add',
        method: 'get',
        data: params
    })
}


/**
 * 家教个人信息修改
 * 
 * @method PostTutorActionUpdate
 * 
 * @param {Object} params 
 * 
 * @example 
 * { 
 * }
 *
 * @return 
 * {
    "error": "no response from server"
    }
 */
export function PostTutorActionUpdate (params) {
    return request({
        url: '/tutor/action/update',
        method: 'post',
        params
    })
}

/**
 * 家教信息详情
 * 
 * @method GetTutorActionDetails
 * 
 * @param {String} tutor_id  
 * 
 * @example 
    * {
        tutor_id (string, optional), // 家教ID
 * }
 *
 * @return 
 * {
    "error": "no response from server"
    }
 */
export function GetTutorActionDetails (params) {
    return request({
        url: '/tutor/action/details',
        method: 'get',
        params
    })
}




/**
 *  --------------------------------------- 家教简历 End ---------------------------------------
 */




/**
 * 退出登录
 * @param callback
 */
export function logout (callback) {
    requestHandle(request({
        url: `${API_PREFIX}/logout`,
        method: 'get'
    }), callback);
}



/**
 *  --------------------------------------- 忘记密码 Start ---------------------------------------
 */

/**
 * 忘记密码
 * @param params
 */
export function GetPictCode (params) {
    return request({
        url: '/anonymous/action/pictCode',
        method: 'get',
        params
    })
}
/**
 * 发送验证码
 * @param params
 */
export function getForgetPassword (params) {
    return request({
        url: '/anonymous/action/phoneCode',
        method: 'get',
        params
    })
}


/**
 * 忘记密码
 * @param callback
 */
export function postFindPwd (params) {
    return request({
        url: '/anonymous/action/findPwd',
        method: 'post',
        params
    })
}

/**
 *  --------------------------------------- 忘记密码 End ---------------------------------------
 */


/**
 *  --------------------------------------- 上传头像 Start ---------------------------------------
 */

/**
 * 上传头像
 * @param params
 */
export function postUpdatePhoto (params) {
    return request({
        url: '/tutor/action/updatePhoto',
        method: 'post',
        params
    })
}


/**
 *  --------------------------------------- 上传头像 End ---------------------------------------
 */


/**
 *  --------------------------------------- 修改密码 Start ---------------------------------------
 */

/**
 * 家长修改密码
 * @param {string}  id 用户ID
 * @param {string}  oldPwd   旧密码
 * @param {string}  newPwd   新密码
 */
export function postParentUpdatePwd (params) {
    return request({
        url: '/parent/action/updatePwd',
        method: 'post',
        params
    })
}


/**
 * 家教修改密码
 * @param {string}  id 用户ID
 * @param {string}  oldPwd   旧密码
 * @param {string}  newPwd   新密码
 */
export function postTutorUpdatePwd (params) {
    return request({
        url: '/tutor/action/updatePwd',
        method: 'post',
        params
    })
}

/**
 *  --------------------------------------- 修改密码 End ---------------------------------------
 */